﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace OpenRPOSMetro
{
    public sealed partial class StatusDialog : Page
    {
        public event EventHandler CloseRequested;
        private List<StatusData> statusDataList = new List<StatusData>();
        public StatusDialog()
        {
            this.InitializeComponent();
        }
        public void init()
        {
            // Iterate over all open orders
            foreach (ServiceReferenceOpenRPOS.OrderSummary os in Globals.OrderSummaryRecords.OrderBy(x => x.col_ID))
            {
                // Get the status of each open order
                StatusData sd = new StatusData();
                sd.OrderNumber = (os.col_ID % 100).ToString();
                sd.Server = Globals.LoginRecords.Where(x => x.col_ID == os.col_LoginID).First().col_DisplayName;
                // Determine the status
                switch (os.col_Status)
                {
                    case Globals.k_int_status_open:
                        sd.Status = "Open";
                        break;
                    case Globals.k_int_status_sent:
                        sd.Status = "Sent";
                        break;
                    case Globals.k_int_status_ready:
                        sd.Status = "Ready";
                        break;
                    case Globals.k_int_status_delivered:
                        sd.Status = "Delivered";
                        break;
                    case Globals.k_int_status_closing:
                        sd.Status = "Closing";
                        break;
                    default:
                        sd.Status = "Unknown";
                        break;
                }
                // Add status information to the list
                statusDataList.Add(sd);
            }
            // Display data
            lvStatus.ItemsSource = statusDataList;
        }
        private void btnDone_Click(object sender, RoutedEventArgs e)
        {
            // Close the dialog
            if (this.CloseRequested != null)
            {
                this.CloseRequested(this, EventArgs.Empty);
            }
        }
    }
    public class StatusData
    {
        public string Server { get; set; }
        public string OrderNumber { get; set; }
        public string Status { get; set; }
    }
}
